package com.itheima.app.controller;

import com.itheima.app.interceptor.UserHolder;
import com.itheima.app.manager.MessageManager;
import com.itheima.vo.HuanXinVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
public class MessageController {
    @Autowired
    private MessageManager messageManager;

    @GetMapping("/huanxin/user")//认证环信用户信息
    public ResponseEntity huanxinAuthc() {
        HuanXinVo huanXinVo = new HuanXinVo();
        huanXinVo.setUsername(UserHolder.get().getId().toString());
        huanXinVo.setPassword("123456");
        return ResponseEntity.ok(huanXinVo);
    }

    @PostMapping("/tanhua/strangerQuestions")//打招呼
    public void greetingWay(@RequestBody Map<String, String> map) {
        Long jiaRenUserId = Long.parseLong(map.get("userId"));
        String reply = map.get("reply");
        messageManager.greetingWay(jiaRenUserId, reply);
    }

    @PostMapping("/messages/contacts")//添加（好友）联系人
    public void AddContact(@RequestBody Map<String, String> map) {
        long friendId = Long.parseLong(map.get("userId"));
        messageManager.AddContact(friendId);
    }

    @GetMapping("/messages/contacts")//查询联系人列表
    public ResponseEntity findContacts(@RequestParam(value = "page", defaultValue = "1") Integer pageNum,
                                       @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
        return messageManager.findContacts(pageNum, pageSize);
    }

    @GetMapping("messages/likes")//查询点赞列表
    public ResponseEntity findLikes(@RequestParam(value = "page", defaultValue = "1") Integer pageNum,
                                    @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
        Integer commentType = 1;
        return messageManager.findCommentList(pageNum, pageSize, commentType);
    }

    @GetMapping("messages/loves")//查询喜欢列表
    public ResponseEntity findLoves(@RequestParam(value = "page", defaultValue = "1") Integer pageNum,
                                    @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
        Integer commentType = 3;
        return messageManager.findCommentList(pageNum, pageSize, commentType);
    }

    @GetMapping("messages/comments")//查询评论列表
    public ResponseEntity findComments(@RequestParam(value = "page", defaultValue = "1") Integer pageNum,
                                       @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
        Integer commentType = 2;
        return messageManager.findCommentList(pageNum, pageSize, commentType);
    }

    @GetMapping("/messages/announcements")//查询公告
    public ResponseEntity findAnnouncements(@RequestParam(value = "page", defaultValue = "1") Integer pageNum,
                                            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize){
        return messageManager.findAnnouncements(pageNum,pageSize);
    }
}